<?php
namespace app\common\model;

use org\util\TreeUtil;
use think\Db;

class TradeModel extends BaseModel
{
    protected $name = 'trade'; //定义用户表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = false;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改

    /*读取器*/
    /*修改器*/

    /**
     * 更新缓存
     * @return bool
     */
    public function updateCache()
    {
        $list = Db::table('trade')->order('trade_sort')->select()->toArray(); //避免走模型读取器
        $list = \org\Util\TreeUtil::tree($list, 'trade_name', 'trade_id', 'trade_pid');
        $data     = array();
        foreach ($list as $v) {
            $isSon           = \org\util\TreeUtil::hasChild($list, $v['trade_id'], 'trade_pid');
            $v['is_son']     = $isSon;
            $data[$v['trade_id']] = $v;
        }
        cache('trade',$data);
        return true;
    }
}